package com.gl.saasservice.repository;

import com.gl.saasservice.entity.AppUser;
import com.gl.saasservice.entity.User;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface QYUserRepository extends PagingAndSortingRepository<User, String>, JpaSpecificationExecutor<User> {

    User findByName(String name);

    @Query("from User where mobile=:mobile and status != 2")
    User findByMobile(String mobile);

    List<User> findByIdIn(List<String> id);

    int countByStatusIn(List<Short> statusList);

    @Modifying
    @Query(value = "update saas_user m set m.name= ?1 ,m.mobile=?2 where m.mobile= ?3",nativeQuery = true)
    public int saveNameAndMobile(String name,String mobile,String oldmobile);

    @Modifying
    @Query(value = "update saas_user m set m.name= ?1 ,m.mobile=?2 where m.id= ?3",nativeQuery = true)
    public int updateUserPhone(String name,String mobile,String id);

    User findByIdInAndType(List<String> ids, Short type);
}
